package com.abei.gas.controller;

import com.abei.gas.entity.Card;
import com.abei.gas.entity.User;
import com.abei.gas.service.UserService;
import com.abei.gas.vo.DataVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理相关接口")
public class UserController {
    @Autowired
    private UserService userservice;
    @GetMapping("/findAll")
    public DataVo<User> findAll(Integer page,Integer limit)
    {
        return userservice.findAll(page,limit);
    }

    @RequestMapping("/deleteById")
    public void deleteById(HttpServletRequest request){
        String id = request.getParameter("id");
        userservice.deleteById(id);
    }
    /*
     * 添加
     */
    @PostMapping("/insert")
    public void insert(@RequestBody User user){
        userservice.Insert(user);
    }

    @RequestMapping("/updateById")
    public void updateById(@RequestBody User user){
        String number=user.getId();
        userservice.Update(number,user);
    }

    //搜索
    @GetMapping("/selectById")
    public DataVo<User> selectById(HttpServletRequest request) {
        String id = request.getParameter("id");
        return userservice.findById(id);
    }
}
